package com.iatinspur.learn;


import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.List;

/**
 * 26集 gc讲解的开始
 *
 * 27集:gc 方法区的垃圾回收
 *    回收条件
 *    1.此类所有的实例对象已经被回收，在堆中不存在任何类的实例对象以及子类对象
 *    2.加载该类的类加载器已经被回收
 *    3.该类对应的java.lang.Class没有任何地方被应用
 *
 *    -XX:+TraceClassLoading -XX:+TraceClassUnloading
 *
 *
 *    [Loaded com.iatinspur.pojo.MyIml1 from file:D:/myClass/]
 *    [Unloading class com.iatinspur.pojo.MyIml1 0x00000007c0437028]
 *
 *
 *
 */
public class Learn_24_JVM {
    public static void main(String[] args) throws MalformedURLException, ClassNotFoundException, InstantiationException, IllegalAccessException {

        List<Object> obs = new ArrayList<Object>();
        List<Class> classes = new ArrayList<Class>();

        List<ClassLoader> loaders = new ArrayList<ClassLoader>();

        while(true){
            URLClassLoader loader = new URLClassLoader(new URL[]{
                    new URL("file:D:\\myClass\\")
            });

            Class<?>clazz =loader.loadClass("com.iatinspur.pojo.MyIml1");
            Object o = clazz.newInstance();
          //  obs.add(o);
          //  classes.add(clazz);
            loaders.add(loader);
            System.gc();
        }
    }
}








